using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DatabaseManager.Util.Exporters
{
    delegate void DataExportProcessHandler(object sender, DataExportProcessEventArgs e);

    abstract class DataExportBase
    {
        protected string _fileName;
        protected DataTable _dataTable;

        public abstract event DataExportProcessHandler DataExportProcess;

        public DataExportBase(DataTable dataTable, string fileName)
        {
            _fileName = fileName;
            _dataTable = dataTable;
        }

        abstract public void Export();

        public string FileName 
        { 
            get
            {
                return _fileName;
            } 
        }

        public DataTable DataTable
        {
            get
            {
                return _dataTable;
            }
        }

        protected string ObjectToString(object value)
        {
            string convertedValue = string.Empty;

            if (value.GetType() == typeof(byte[]))
            {
                convertedValue = Convert.ToBase64String((byte[])value, Base64FormattingOptions.InsertLineBreaks);
            }
            else
            {
                convertedValue = value.ToString();

                if (convertedValue == "\0")
                    convertedValue = string.Empty;
            }

            return convertedValue;
        }
    }

    class DataExportProcessEventArgs : EventArgs
    {
        private int _currentRowIndex;
        private int _rowCount;

        internal DataExportProcessEventArgs(int currentRowIndex, int rowCount)
        {
            _currentRowIndex = currentRowIndex;
            _rowCount = rowCount;
        }

        public int RowCount
        {
            get { return _rowCount; }
        }

        public int CurrentRowIndex
        {
            get { return _currentRowIndex; }
        }
    }
}
